{% extends 'base.html' %}

{% block content %}
<link rel="stylesheet" href="/css/article_publish.css">
<script type="text/javascript" src="/ue/ueditor.config.js"></script>
<script type="text/javascript" src="/ue/ueditor.all.min.js"></script>
<script type="text/javascript" src="/ue/lang/zh-cn/zh-cn.js"></script>
<div class="big">
    <div class="box1">
        <label for="headline">文章标题:</label>
        <input type="text" id="headline">
    </div>
    <div class="box2">
        <script id="content" name="content" type="text/plain">

        </script>
    </div>
    <div class="box3">
        <form action="">
        <span>类型:</span>
        <label for="type">
            <select name="" id="type">
                <option value="1">PHP开发</option>
                <option value="2">Java开发</option>
                <option value="3">Python开发</option>
                <option value="4">Web前端</option>
                <option value="5">测试开发</option>
                <option value="6">数据科学</option>
                <option value="7">网络安全</option>
                <option value="8">蜗牛杂谈</option>
            </select>
        </label>
            <span>积分:</span>
            <label for="credit">
                <select id="credit">
                    <option value="0">免费</option>
                    <option value="1">1分</option>
                    <option value="2">2分</option>
                    <option value="5">5分</option>
                    <option value="10">10分</option>
                    <option value="20">20分</option>
                    <option value="50">50分</option>

                </select>
            </label>
             <button class="ex">保存草稿</button>
            <button class="ey" onclick="doUserPost()" type="button">发布文章</button>
        </form>
    </div>

</div>
<script type="text/javascript">
    var ue =UE.getEditor('content',{
        initialFrameHeight: 400,
        autoHeightEnabled: true,
        serverUrl: '/uedit'
    })
</script>
<script>
    function doUserPost() {
        var headline = $("#headline").val().trim();
        var contentPlain = UE.getEditor("content").getContentTxt();
        var type = $("#type").val();
        var credit = $("#credit").val();

        var param = "headline="+headline;
        param += "&credit="+credit;
        param += "&type="+type;
        param += "&content="+contentPlain;
        $.post('/add_article', param, function (data){
            if(data == 'OK'){
                location.href='/';
            }else {
                alert('文章发布失败')
            }
        })

    }
</script>
<script src="/js/jquery-3.1.1.js"></script>
{% endblock %}